package com.spark.config;

import com.spark.common.ExchangeName;
import com.spark.common.QueueNames;
import com.spark.common.RoutingKeyName;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author sc
 * @DATE 2024/5/23 11:19
 * @Description:
 * @Version 1.0
 */
@Configuration
public class RabbitMqQueueConfig {

    @Bean
    public DirectExchange defaultExchange() {
        return new DirectExchange(ExchangeName.DEFAULT.name());
    }

    @Bean
    public DirectExchange busTypeMsgDirectExchange() {
        return new DirectExchange(ExchangeName.NOTIFY_MSG.name());
    }

    @Bean
    public Queue busTypeMsgQueue() {
        return new Queue(QueueNames.BUS_TYPE_MSG_QUEUE, true);
    }


    @Bean
    public Binding notifyMsgQueueBinding() {
        return BindingBuilder
                .bind(busTypeMsgQueue())
                .to(busTypeMsgDirectExchange())
                .with(RoutingKeyName.BUS_TYPE_MSG);
    }

}
